<template>
	<div>
		<el-row :gutter="10">
			<el-col :span="5">
				<el-input v-model="search.name" placeholder="请输入要查询的用户名"></el-input>
			</el-col>
			<el-col :span="19">
				<el-button type="primary" icon="el-icon-search" plain @click="searchData()">搜索</el-button>
				<el-button type="primary" icon="el-icon-circle-plus-outline" plain @click="add()">添加康复计划</el-button>
				<el-button type="warning" icon="el-icon-delete" plain @click="batchdel()">批量删除</el-button>
			</el-col>
		</el-row>
		<el-table :data="result.tableData" style="width: 100%" @selection-change="handleSelectionChange">
			<el-table-column type="selection">
			</el-table-column>
			<el-table-column label="序号" prop="kfId">
			</el-table-column>
			<el-table-column label="档案编号" prop="recordNum">
			</el-table-column>
			<el-table-column label="姓名" prop="name">
			</el-table-column>
			<el-table-column label="病因" prop="pathogen">
			</el-table-column>
			<el-table-column label="治疗处方" prop="therapeuticRegimen">
			</el-table-column>
			<el-table-column label="主治医生" prop="doctor">
			</el-table-column>
			<el-table-column label="治疗医师" prop="physician">
			</el-table-column>
			<el-table-column label="开始时间" prop="startTime">
			</el-table-column>
			<el-table-column label="预计康复周期" prop="kfPeriod">
			</el-table-column>
			<!-- <el-table-column
        label="是否有效"
        width="100"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.active === 1">有效</span>
          <span v-else>无效</span>
        </template>
      </el-table-column> -->
			<el-table-column label="操作" width="220px">
				<template slot-scope="scope">
					<template>
						<el-button size="mini" @click="handleEdit(scope.row.kfId)">编辑</el-button>
						<el-button size="mini" type="danger" @click="handleDelete(scope.row.kfId)">删除</el-button>
					</template>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination style="margin-top:20px;" background layout="prev, pager, next" :page-count="result.pages"
			:current-page.sync="query.current" :page-size="query.size" @current-change="getData()">
		</el-pagination>
		<el-dialog :title="title" :visible.sync="show" :close-on-click-modal="false" width="500px">
			<KfProgramEdit v-if="show" :show.sync="show" @getData="getData()" :editkfId="editkfId">
			</KfProgramEdit>
		</el-dialog>
	</div>
</template>

<script>
	import KfProgramEdit from '@/views/kf_program/edit'
	export default {
		name: 'KfProgram',
		data() {
			return {
				search: {
					name: ''
				},
				query: {
					name: '',
					current: 1,
					size: 4
				},
				result: {
					tableData: [],
					pages: 0
				},
				show: false,
				editkfId: null,
				selectedrow: [],
				title: ''
			}
		},
		components: {
			KfProgramEdit,
		},
		created() {
			this.getData()
		},
		methods: {
			getData() {
				this.axios.get('/kfProgram/list', response => {
					this.result.tableData = response.obj.records
					this.result.pages = response.obj.pages
				}, this.query)
			},
			searchData() {
				this.query.name = this.search.name
				this.query.current = 1
				this.getData()
			},
			handleEdit(kfId) {
				this.title = '修改康复计划'
				this.editkfId = kfId
				this.show = true
			},
			add() {
				this.title = '添加康复计划'
				this.editkfId = null
				this.show = true
			},
			handleDelete(kfId) {
				this.axios.del('/kfProgram/delete/' + kfId, response => {
					this.getData()
				}, {
					kfId: kfId
				})
			},
			handleSelectionChange(val) {
				// val参数为所有选中行的数据
				this.selectedrow = val
			},
			batchdel() {
				if (this.selectedrow.length === 0) {
					this.$message('没有任何被选中的数据');
				} else {
					const ids = []
					console.log(this.selectedrow.length)
					for (let i = 0; i < this.selectedrow.length; i++) {
						ids.push(this.selectedrow[i].kfId)
					}
					this.axios.get('/kfProgram/batchdel', response => {
						this.getData()
					}, {
						id: ids.join(",")
					})
				}
			}
		}
	}
</script>
<style scoped>
</style>
